$(function(){
	// text-box 滑出 滑入
	$(".teacher, .schoollife, .potency").mouseover(function(){
		$(this).children(".text-box").stop().slideDown();
	})
	
	$(".teacher, .schoollife, .potency").mouseout(function(){
		$(this).children(".text-box").stop().slideUp();
	})
	
	
	//header滑动 start
	let moveOverTheHeader_range = $('#header').height()-$('#top_nav').height();
	let isMoveOverJustNow = false;
	
	function moveOverTheHeader() {
		$(window).scroll(function(even){
			if ($(document).scrollTop() > 0)
			{
				isMoveOverJustNow = true;
				$(this).off(even);
				$('html').stop().animate({
					scrollTop: moveOverTheHeader_range
				}, 500, moveToTheHeader); //animate()
			}
		})//$(window).scroll
	};//moveOverTheHeader()
	
	moveOverTheHeader();
	
	let moveToTheHeader_range = $('#header').height();
	function moveToTheHeader() {
		let handle = $(window).scroll(function(even){
			if ($(document).scrollTop() < moveToTheHeader_range) {
				if (isMoveOverJustNow) return;
				$(this).off(even);
				$('html').stop().animate({
					scrollTop: 0
				}, 600, moveOverTheHeader);//animate()
			} else {
				isMoveOverJustNow = false;
			}
		})//$(window).scroll
	}//moveToTheHeader() 
	//header滑动 end
	
	//top-nav 改变定位 start
	let navChangeChance = moveOverTheHeader_range;
	$(window).scroll(function(){
		//top-nav 变固定
		if ($(document).scrollTop() >= navChangeChance && !isNavFixed) {
			// changeNavToFixed();
			changeNavCssPosition();
			console.log('nav fixed');
		} else if($(document).scrollTop() < navChangeChance && isNavFixed) {
			// changeNavToAbsolute();
			changeNavCssPosition();
			console.log('nav absolute');
		}
	})//window.scroll
	let isNavFixed = false;
	function changeNavCssPosition() {
		let nav = $("#top_nav");
		if (isNavFixed) {
			isNavFixed = false;
			nav.fadeOut(function() {
				changeNavState(nav);
				nav.css("position", "absolute").fadeIn();
			});
		} else {
			isNavFixed = true;
			nav.fadeOut(function() {
				changeNavState(nav);
				nav.css("position", "fixed").fadeIn();
			});
		}
	}
	
	function changeNavState(nav) {
		//改成downLink和downNav
		nav.toggleClass("downNav").find("a").toggleClass("downLink");
	}
	//top-nav 改变定位 end
	
	
	//guide start
	let guide = $("#guide");
	$(document).mousemove(function(even){
		guide.offset({
			top: even.pageY,
			left: even.pageX
		});//offset
	})
	
	$("#whySelect .w>div").hover(function(){
		guide.stop().fadeIn();
		guide.html($(this).attr("text"));
	}, function() {
		guide.stop().fadeOut();
	})
	
	$("#preview .w>div").hover(function(){
		guide.stop().fadeIn();
		guide.html($(this).attr("text"));
	}, function() {
		guide.stop().fadeOut();
	})
	//guide end
	
	//viewer start
	let viewer = $("#viewer");
	$("#preview img").click(function(){
		console.log($(this).attr("src"));
		viewer.stop().fadeIn();
		viewer.find('img').attr("src", $(this).attr("src"));
	});
	
	viewer.click(function(){
		$(this).stop().fadeOut();
	})
})//$()